package com.example.springboot_calculator_mysql.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.springboot_calculator_mysql.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
@RestController
public class CalculatorController {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @GetMapping("/add")
    public int add(int a,int b){
        jdbcTemplate.update("INSERT INTO calc_record (operand1,operator,operand2,result) VALUES (?,'+',?,?)",a,b,a+b);
        return a+b;
    }
    @GetMapping("/sub")
    public int sub(int a,int b){
        jdbcTemplate.update("INSERT INTO calc_record (operand1,operator,operand2,result) VALUES (?,'-',?,?)",a,b,a-b);
        return a-b;
    }
    @GetMapping("/multiply")
    public int multiply(int a,int b){
        jdbcTemplate.update("INSERT INTO calc_record (operand1,operator,operand2,result) VALUES (?,'*',?,?)",a,b,a-b);
        return a*b;
    }
    @GetMapping("/division")
    public int division(int a,int b){
        jdbcTemplate.update("INSERT INTO calc_record (operand1,operator,operand2,result) VALUES (?,'/',?,?)",a,b,a-b);
        return a/b;
    }
}
